#!/bin/sh
DOCUMENT_NAME=config_file
FILE_NAMES="/home/caiwang213/.ssh /home/caiwang213/.bashrc  /home/caiwang213/.vimrc /etc/samba/smb.conf /etc/man_db.conf /etc/fstab /etc/profile /etc/yum.repos.d/"

set $(who am i)
USER_NAME=$1


set $(date)
YEAR=$6
case $2 in
	Jan)
		MONTH="01"
		;;
	Feb)
		MONTH="02"
		;;
	Mar)
		MONTH="03"
		;;
	Apr)
		MONTH="04"
		;;
	May)
		MONTH="05"
		;;
	Jun)
		MONTH="06"
		;;
	Jul)
		MONTH="07"
		;;
	Aug)
		MONTH="08"
		;;
	Sep)
		MONTH="09"
		;;
	Oct)
		MONTH="10"
		;;
	Nov)
		MONTH="11"
		;;
	Dec)
		MONTH="12"
		;;
	*)
		echo "Invalid month"
		exit 1
		;;
esac

DAY=$(echo $3 | gawk '{if(length($1) == 1) print "0"$1;if(length($1) == 2) printf $1}')
HOUR=$(echo $4 | gawk '{print substr($1,1,2)}')
MINUTE=$(echo $4 | gawk '{print substr($1,4,2)}')
SECOND=$(echo $4 | gawk '{print substr($1,7,2)}')


DATE_TIME_STRING=${YEAR}${MONTH}${DAY}_${HOUR}${MINUTE}${SECOND}
#TAR_NAME=${USER_NAME}_${DOCUMENT_NAME}_${DATE_TIME_STRING}.tar.gz
TAR_NAME=${DOCUMENT_NAME}_${DATE_TIME_STRING}.tar.gz


echo -e -n "backup $DOCUMENT_NAME..."
if tar -zcvf ${TAR_NAME} ${FILE_NAMES} ;then
	echo "($TAR_NAME) ok!"
	cd ${CUR_DIR}
else
	echo "($TAR_NAME) failed!"
	cd ${CUR_DIR}
	exit 1
fi

echo "backup over!"
